I need to write a reliable transport protocol python program that uses UDP to handle packet loss, corruption, duplication and delay. I am new to coding and get the overall idea, but I don’t know many techniques to solving the problem.1 2 Source: Python..
I am working on implementing an SMTP protocol and am running into some issues regarding this case. For example, if a working SMTP protocol receives the commands: RCPT TO: [email protected] RCPT TO: [email protected] Would two emails be sent or just one? Source: Python..
I know the inheritance in class. Every methods which a superclass has is inherited to its subclass. So unless needed particularly, the subclass doesn’t have to implement the inherited methods again. But I want to make sure a subclass to re-implement all the methods which a superclass has. The point is that all classes in ..
from typing_extensions import Protocol class IFoo(Protocol): value: int class Foo(IFoo): @property def value(self) -> int: return 2 _value: int @value.setter def value(self, value: int): self._value = value Pylance in strict mode(basic mode doesn’t) is giving an error at the getter and the setter saying that: "value" overrides symbol of the same name in class "IFoo" ..
I am trying to write a callback protocol that is a supertype of all functions that have a return type ‘str’ and also are able to accept calls with arguments like (first_arg=some_int, second_arg=some_string, third_arg=some_float). The only requirement for functions in this family is that calls that conform to this pattern must be valid. (Some of ..
My question is simple. I have this protocol: class LauncherTemplateConfig(Protocol): … def launch_program_cmd(self, **kwargs) -> list[str]: pass … And this implementation of the protocol, which I would expect mypy passes, but it does not: class MyLauncherTemplateConfig: … def launch_program_cmd( self, some_arg: Optional[Path] = None, another_arg=1 ) -> list[str]: … I would expect the parameters in ..
Suppose I have a protocol Foo. from typing import Protocol, Optional class Foo(Protocol): val: Optional[int] And a function like the following: def func(obj: Foo) -> None: if obj.val is not None: print(obj.val) I would expect that either ImplA and ImplB (shown below) should be an acceptable argument for func, since val: int is a more ..
I want to create a Protocol, in which a field can be implemented by both a simple type and property. For example: class P(Protocol): v: int @dataclass class Foo(P): v: int class Bar(P): @property def v(self) -> int: # ERROR return 1 But the code above doesn’t type check. How should I fix? Source: Python ..
Let’s say I have PEP-544 protocol called Summable : class Summable(Protocol): total_amount: Decimal And I have model Item that implements the Protocol class Item(Summable, models.Model): discount = models.DecimalField( decimal_places=2, validators=[MaxValueValidator(1)], default=Decimal(‘0.00’), max_digits=10 ) price = models.DecimalField( decimal_places=4, validators=[MinValueValidator(0)], max_digits=10 ) @property def total_amount(self): return sel.price – self.price * self.discount class Meta: ordering = [‘id’] I ..
I’ve tried to make a discord bot that would also send emails with invitations and I keep getting errors regarding the email sending from python. Every other command I implemented works even this command without the email sending part the text being actually created as well as the invitation. And of course, I checked multiple ..