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 typehints
class Thing:
x = None
y = None
def __init__(self, x, y):
self.x = x
self.y = y
# Elegant new way
class Thing:
x: str
y: int
def __init__(self, x: str, y: int):
self.x = x
self.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.
Session has some attributes like
genreandrequestwhich should be exposed on the class. Otherwise if aSessionis 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.