„ResolutionFailed: Konnte nicht zu einer Strategie aufgelöst werden; Erwägen Sie die Verwendung von „register_type_stratPython

Python-Programme
Anonymous
 „ResolutionFailed: Konnte nicht zu einer Strategie aufgelöst werden; Erwägen Sie die Verwendung von „register_type_strat

Post by Anonymous »

Trotz:
  • Registrierung von RandColl2 unter Verwendung von st.register_type_strategy mit einem Handler,
  • Code: Select all

    RandColl2[str, int]
    und RandColl2[int, str] sind Instanzen der Typen.GenericAlias, und
  • Code: Select all

    ht.str
    und ht.Str werden als Strategien registriert, das folgende Snippet:

Code: Select all

import typing, types
import hydrox.typing as ht
from hypothesis import strategies as st

st.register_type_strategy(str, st.one_of(st.text(), st.characters()))

for g in ht.HTGenerics.str:
st.register_type_strategy(g, st.from_type(g.__generic__))

print(st.from_type(ht.str))  # one_of(text(), characters())
print(st.from_type(ht.Str))  # one_of(text(), characters())

class RandColl1:
__class_getitem__ = classmethod(types.GenericAlias)

@ht.Generalize(subscriptions=-1)
class RandColl2: ...

def return_collection_strat(t):
raise ValueError(t)

st.register_type_strategy(RandColl1, return_collection_strat)

try:
print(st.from_type(RandColl1[str, int]).example())
except ValueError:
pass  # Passes

try:
print(st.from_type(RandColl1[int, str]).example())
except ValueError:
pass  # Passes

print(isinstance(RandColl2[str, int], types.GenericAlias))  # True
print(isinstance(RandColl2[int, str], types.GenericAlias))  # True
print(typing.get_args(RandColl2[str, int]))  # (ht.str, )
print(typing.get_args(RandColl2[int, str]))  # (, ht.str)

st.register_type_strategy(RandColl2, return_collection_strat)
print(st.from_type(RandColl2[str, int]).example())
print(st.from_type(RandColl2[int, str]).example())
Gibt den folgenden Fehler aus, wenn versucht wird, st.from_type(RandColl2[str, int]).example() und st.from_type(RandColl2[int, str]).example() auszuführen:

Code: Select all

ResolutionFailed: Could not resolve _.RandColl2[ht.str, int] to a strategy; consider using register_type_strategy
Ich dachte, dass Typen.GenericAlias-Instanzen automatisch an die Handler gesendet werden?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post