Skip to content

Commit

Permalink
Improve deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Mar 19, 2023
1 parent 6144597 commit b404bfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pyalex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ class Publisher(OpenAlexEntity):

# deprecated

def Venue(*args, **kwargs):

class Venue(OpenAlexEntity):
warnings.warn("deprecated", DeprecationWarning, stacklevel=2)
pass
# warn about deprecation
warnings.warn(
"Venue is deprecated. Use Sources instead.",
DeprecationWarning,
stacklevel=2,
)

return Source(*args, **kwargs)


class CursorPaginator(object):
Expand Down Expand Up @@ -346,8 +352,7 @@ class Publishers(BaseOpenAlex):

# deprecated


class Venues(BaseOpenAlex):
def Venues(*args, **kwargs):

# warn about deprecation
warnings.warn(
Expand All @@ -356,10 +361,9 @@ class Venues(BaseOpenAlex):
stacklevel=2,
)

url = config.openalex_url + "/venues"
obj = Venue
return Sources(*args, **kwargs)


# aliases
People = Authors
Journals = Venues
Journals = Sources
6 changes: 6 additions & 0 deletions tests/test_pyalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyalex import Authors
from pyalex import Concepts
from pyalex import Institutions
from pyalex import Publishers
from pyalex import Sources
from pyalex import Work
from pyalex import Works
Expand Down Expand Up @@ -332,3 +333,8 @@ def test_ngrams_with_metadata():
r, meta = Works()["W2023271753"].ngrams(return_meta=True)

assert meta["count"] == 1068


def test_random_publishers():

assert isinstance(Publishers().random(), dict)

0 comments on commit b404bfb

Please sign in to comment.