Skip to content

Spec of Session should be fully exposed on class #192

Description

@2e0byo

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions