You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Session has some attributes like genre and request which should be exposed on the class. Otherwise if a Session is mocked (with Mock(spec=Session)) access to these attributes is forbidden. (See the mock docs for a description of this problem and why speccing is important.)
We worked around this on mopidy-tidal with a nasty hack. The test suite rewrite (in progress) subclasses and links to this bug.
All these attribute should be set on the class. Additionally it'd be nice now we have type hints to remove the old 'default None' which causes so many spurious errors and just set the type, like so:
# Bad old way, pre typehintsclassThing:
x=Noney=Nonedef__init__(self, x, y):
self.x=xself.y=y# Elegant new way classThing:
x: stry: intdef__init__(self, x: str, y: int):
self.x=xself.y=y
The typehint work by @arusahni had some pretty heroic workarounds for some of this kind of pattern. A bit of refactoring will make things a lot easier.
I'll implement this at some point if nobody wants to do it first, but it probably won't be for at least a month.
The text was updated successfully, but these errors were encountered:
Some of the None/Optional occurrences are also necessary for the pattern we use for parsing. e.g., Session.parse_album first instantiates an empty Album (i.e., no album ID or other metadata) and then calls the parse() method with the API response object to hydrate the instance. It then returns a copy of itself, which feels like an unnecessary allocation.
I think migrating from this pattern to classmethods (e.g., from_response(cls, api_object)) would allow us to drop the None types that have crept in.
Yes, that should go on the list too. Currently the hydration pattern plays havok with downstream libraries, which either have to assume they got a properly hydrated instance, or have loads of redundant checks. I think the PR for this issue will probably be quite speculative, and we should discuss it carefully.
Session has some attributes like
genre
andrequest
which should be exposed on the class. Otherwise if aSession
is mocked (withMock(spec=Session)
) access to these attributes is forbidden. (See the mock docs for a description of this problem and why speccing is important.)We worked around this on mopidy-tidal with a nasty hack. The test suite rewrite (in progress) subclasses and links to this bug.
All these attribute should be set on the class. Additionally it'd be nice now we have type hints to remove the old 'default None' which causes so many spurious errors and just set the type, like so:
The typehint work by @arusahni had some pretty heroic workarounds for some of this kind of pattern. A bit of refactoring will make things a lot easier.
I'll implement this at some point if nobody wants to do it first, but it probably won't be for at least a month.
The text was updated successfully, but these errors were encountered: