Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name Validation on Positional-Only Parameters #88

Closed
erikvanderwerf opened this issue May 25, 2021 · 1 comment
Closed

Name Validation on Positional-Only Parameters #88

erikvanderwerf opened this issue May 25, 2021 · 1 comment
Labels

Comments

@erikvanderwerf
Copy link

Hello!

I have a generic Serializer class which declares a serialize(...) method. My issue is that the superclass abstract method uses a generic parameter name (o) which is hidden by a positional-only / (PEP570). while I would like to use more descriptive parameter names in my subclasses. All uses of this class will pass-by-position, never by name.

from abc import ABC, abstractmethod
from typing import Generic, TypeVar

from overrides import overrides

T = TypeVar("T")


class Serializer(Generic[T], ABC):
    @abstractmethod
    def serialize(self, o: T, /) -> bytes:
        raise NotImplementedError()


class MyDataSerializer(Serializer[object]):
    @overrides
    def serialize(self, data: object, /) -> bytes:
        pass

The above example raises a TypeError on overrides==6.1.0.

TypeError: MyDataSerializer.serialize: data is not a valid parameter.

I can see the necessity of name-checking when parameter names can be used directly. However, when used with PEP570 I would like to see parameters only validated by the type at each ordinal/position and to ignore the name.

Thanks!

@mkorpela mkorpela added the bug label Oct 7, 2022
@mkorpela
Copy link
Owner

mkorpela commented Oct 8, 2022

Fixed in eb07ca2

@mkorpela mkorpela closed this as completed Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants