Ë
    iKêj,,  ã                   óæ   — d Z ddlZddlZddlmZmZ ddlmZ ddlZ	ddl
mZ ddlmZ dedefd„Zd	„ Z G d
„ de«      Zej&                  d„ «       Z G d„ de«      Z G d„ de«      Z G d„ de«      Zy)a‰  
This module provides codemods based on the :pypi:`LibCST` library, which can
both detect *and automatically fix* issues with code that uses Hypothesis,
including upgrading from deprecated features to our recommended style.

You can run the codemods via our CLI::

    $ hypothesis codemod --help
    Usage: hypothesis codemod [OPTIONS] PATH...

      `hypothesis codemod` refactors deprecated or inefficient code.

      It adapts `python -m libcst.tool`, removing many features and config
      options which are rarely relevant for this purpose.  If you need more
      control, we encourage you to use the libcst CLI directly; if not this one
      is easier.

      PATH is the file(s) or directories of files to format in place, or "-" to
      read from stdin and write to stdout.

    Options:
      -h, --help  Show this message and exit.

Alternatively you can use ``python -m libcst.tool``, which offers more control
at the cost of additional configuration (adding ``'hypothesis.extra'`` to the
``modules`` list in ``.libcst.codemod.yaml``) and `some issues on Windows
<https://github.com/Instagram/LibCST/issues/435>`__.

.. autofunction:: refactor
é    N)Ú	ParameterÚ	signature)ÚClassVar)ÚVisitorBasedCodemodCommandÚcodeÚreturnc                 ó  — t         j                  j                  «       }t        j                  | «      }t	        |«      t        |«      t        |«      t        |«      g}|D ]  }|j                  |«      }Œ |j                  S )a'  Update a source code string from deprecated to modern Hypothesis APIs.

    This may not fix *all* the deprecation warnings in your code, but we're
    confident that it will be easier than doing it all by hand.

    We recommend using the CLI, but if you want a Python function here it is.
    )
ÚcstÚcodemodÚCodemodContextÚparse_moduleÚ#HypothesisFixPositionalKeywonlyArgsÚ HypothesisFixComplexMinMagnitudeÚHypothesisFixHealthCheckAllÚ HypothesisFixCharactersArgumentsÚtransform_moduler   )r   ÚcontextÚmodÚ
transformsÚ	transforms        ú^/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/hypothesis/extra/codemods.pyÚrefactorr   4   sw   € ô �k‰k×(Ñ(Ó*€GÜ
×
Ñ
˜4Ó
 €Cä+¨GÓ4Ü(¨Ó1Ü# GÓ,Ü(¨Ó1ð	4€Jð  ò .ˆ	Ø×(Ñ(¨Ó-‰ð.à�8‰8€Oó    c                 óf   ‡ — t        j                  t        j                  j                  ˆ fd„«      S )Nc                 ó,   •— t        ˆfd„| D «       «      S )Nc              3   ó<   •K  — | ]  }|j                   ‰k(  –— Œ y ­w)N©Úname)Ú.0Únr   s     €r   ú	<genexpr>z3match_qualname.<locals>.<lambda>.<locals>.<genexpr>Q   s   øè ø€ Ò@°˜aŸf™f¨�nÑ@ùs   ƒ)Úall)Ú	qualnamesr   s    €r   ú<lambda>z match_qualname.<locals>.<lambda>Q   s   ø€ œ#Ó@°iÔ@Ó@€ r   )ÚmÚMatchMetadataIfTruer
   ÚmetadataÚQualifiedNameProviderr   s   `r   Úmatch_qualnamer)   I   s+   ø€ ô × Ñ Ü�‰×*Ñ*ó 	Aóð r   c                   ó    — e Zd ZdZdZej                  j                  fZ e	j                   e	j                   ed«      ¬«      «      d„ «       Zy)r   a&  Fix a deprecated min_magnitude=None argument for complex numbers::

        st.complex_numbers(min_magnitude=None) -> st.complex_numbers(min_magnitude=0)

    Note that this should be run *after* ``HypothesisFixPositionalKeywonlyArgs``,
    in order to handle ``st.complex_numbers(None)``.
    zAFix a deprecated min_magnitude=None argument for complex numbers.ú%hypothesis.strategies.complex_numbers)r'   c           	      óò   — t        j                  |t        j                  t        j                  d«      t        j                  d«      ¬«      «      r%|j	                  t        j                  d«      ¬«      S |S )NÚmin_magnitudeÚNone)ÚkeywordÚvalueÚ0©r0   )r%   ÚmatchesÚArgÚNameÚwith_changesr
   ÚInteger©ÚselfÚoriginal_nodeÚupdated_nodes      r   Ú	leave_Argz*HypothesisFixComplexMinMagnitude.leave_Arga   sV   € ô �9‰9Øœ!Ÿ%™%¬¯©¨Ó(?ÄqÇvÁvÈfÃ~ÔVô
ð  ×,Ñ,´3·;±;¸sÓ3CÐ,ÓDÐDØÐr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚDESCRIPTIONr
   r'   r(   ÚMETADATA_DEPENDENCIESr%   Úcall_if_insideÚCallr)   r<   © r   r   r   r   U   sU   „ ñð V€KØ Ÿ\™\×?Ñ?ÐAÐà€Q×ÑØˆ�‰™Ð'NÓOÔPóñóñr   r   c                 ój   — | j                  dd«      \  }}t        t        j                  |«      |«      S )Nú.é   )ÚrsplitÚgetattrÚ	importlibÚimport_module)Úimport_pathr   Úfns      r   Úget_fnrO   l   s0   € à× Ñ   aÓ(�G€CˆÜ”9×*Ñ*¨3Ó/°Ó4Ð4r   c                   óL   — e Zd ZdZdZej                  j                  fZdZ	d„ Z
y)r   a/  Fix positional arguments for newly keyword-only parameters, e.g.::

        st.fractions(0, 1, 9) -> st.fractions(0, 1, max_denominator=9)

    Applies to a majority of our public API, since keyword-only parameters are
    great but we couldn't use them until after we dropped support for Python 2.
    z;Fix positional arguments for newly keyword-only parameters.)-zhypothesis.targetzhypothesis.findzhypothesis.extra.lark.from_larkzhypothesis.extra.numpy.arraysz#hypothesis.extra.numpy.array_shapesz.hypothesis.extra.numpy.unsigned_integer_dtypesz%hypothesis.extra.numpy.integer_dtypesz&hypothesis.extra.numpy.floating_dtypesz,hypothesis.extra.numpy.complex_number_dtypesz(hypothesis.extra.numpy.datetime64_dtypesz)hypothesis.extra.numpy.timedelta64_dtypesz)hypothesis.extra.numpy.byte_string_dtypesz,hypothesis.extra.numpy.unicode_string_dtypesz#hypothesis.extra.numpy.array_dtypesz$hypothesis.extra.numpy.nested_dtypesz'hypothesis.extra.numpy.valid_tuple_axesz+hypothesis.extra.numpy.broadcastable_shapeszhypothesis.extra.pandas.indexeszhypothesis.extra.pandas.serieszhypothesis.extra.pandas.columnsz#hypothesis.extra.pandas.data_frameszhypothesis.provisional.domainsz-hypothesis.stateful.run_state_machine_as_testzhypothesis.stateful.rulezhypothesis.stateful.initializeúhypothesis.strategies.floatszhypothesis.strategies.listszhypothesis.strategies.setsz hypothesis.strategies.frozensetszhypothesis.strategies.iterablesz"hypothesis.strategies.dictionariesú hypothesis.strategies.characterszhypothesis.strategies.textz hypothesis.strategies.from_regexzhypothesis.strategies.binaryzhypothesis.strategies.fractionszhypothesis.strategies.decimalszhypothesis.strategies.recursiver+   zhypothesis.strategies.sharedzhypothesis.strategies.uuidszhypothesis.strategies.runnerzhypothesis.strategies.functionszhypothesis.strategies.datetimeszhypothesis.strategies.timesc           	      ó®  — | j                  t        j                  j                  |«      }|D �ch c]  }|j                  ’Œ }}t        |«      dk7  s“|j                  | j                  «      rxt        j                  |t        j                  t        j                  t        j                  «       «      t        j                  d¬«      t        j                  «       g¬«      «      s|S 	 t        t        |Ž «      j                   j#                  «       }|dhk(  r|D �cg c]  }|j                  dk7  sŒ|‘Œ }}t        |j&                  «      t        |«      kD  r|S t        j(                  t        j*                  d«      t        j*                  d«      ¬«      }t-        ||j&                  d	¬
«      D ��	cg c]k  \  }}	|	j.                  s(|	j0                  s|j2                  t4        j6                  ur|	n/|	j9                  t        j:                  |j                  «      |¬«      ‘Œm }
}}	|j9                  |
¬«      S c c}w # t$        $ r |cY S w xY wc c}w c c}	}w )z(Convert positional to keyword arguments.rH   N©r/   ©ÚfuncÚargsrQ   Úallow_subnormalÚ )Úwhitespace_beforeÚwhitespace_afterF)Ústrict)r/   Úequal©rW   )Úget_metadatar
   r'   r(   r   ÚlenÚintersectionÚkwonly_functionsr%   r3   rD   ÚDoesNotMatchr4   Ú
ZeroOrMorer   rO   Ú
parametersÚvaluesÚModuleNotFoundErrorrW   ÚAssignEqualÚSimpleWhitespaceÚzipr/   ÚstarÚkindr   ÚKEYWORD_ONLYr6   r5   )r9   r:   r;   r'   Úqnr#   ÚparamsÚpÚassign_nospaceÚargÚnewargss              r   Ú
leave_Callz.HypothesisFixPositionalKeywonlyArgs.leave_Call®   só  € à×$Ñ$¤S§\¡\×%GÑ%GÈÓWˆØ'/Ö0 �R—W“WÐ0ˆ	Ð0ô �	‹N˜aÒØ×)Ñ)¨$×*?Ñ*?Ô@Ü—9‘9ØÜ—‘ÜŸ™¬¯©«Ó1ÜŸ%™%¨Ô-¬q¯|©|«~Ð>ôôð  Ðð
	 Üœv yÐ1Ó2×=Ñ=×DÑDÓFˆFð Ð7Ð8Ò8Ø!'ÖG˜A¨1¯6©6Ð5FÓ+F’aÐGˆFÐGäˆ|× Ñ Ó!¤C¨£KÒ/ØÐô Ÿ™Ü!×2Ñ2°2Ó6Ü ×1Ñ1°"Ó5ô
ˆô ˜f l×&7Ñ&7ÀÔF÷
ñ ��3ð —;’; #§(¢(¨a¯f©f¼I×<RÑ<RÑ.Rñ à×%Ñ%¬c¯h©h°q·v±vÓ.>ÀnÐ%ÓUñVð
ˆñ 
ð ×(Ñ(¨gÐ(Ó6Ð6ùò[ 1øô* #ò 	 ØÒð	 üò Hùó
s*   ¯H6Ã()H; ÄIÄ0IÆ1A0IÈ;I	ÉI	N)r=   r>   r?   r@   rA   r
   r'   r(   rB   rb   rt   rE   r   r   r   r   r   s0   „ ñð P€KØ Ÿ\™\×?Ñ?ÐAÐð.Ðó`07r   r   c            
       óÊ   — e Zd ZdZdZ ej                   ej                   ej                   ej                  d«       ej                  d«      «      g ¬«      «      d„ «       Z
y)r   z0Replace HealthCheck.all() with list(HealthCheck)ÚHealthCheckr"   rU   c                 óž   — |j                  t        j                  d«      t        j                  t        j                  d«      ¬«      g¬«      S )NÚlistrv   r2   rU   )r6   r
   r5   r4   r8   s      r   Úreplace_healthcheckz/HypothesisFixHealthCheckAll.replace_healthcheckæ   s>   € à×(Ñ(Ü—‘˜&Ó!Ü—'‘'¤§¡¨Ó 7Ô8Ð9ð )ó 
ð 	
r   N)r=   r>   r?   r@   rA   r%   ÚleaverD   Ú	Attributer5   ry   rE   r   r   r   r   á   sX   „ Ù:àD€Kà€Q‡W�WˆVˆQ�V‰V˜˜Ÿ™ V Q§V¡V¨MÓ%:¸F¸A¿F¹FÀ5»MÓJÐQSÔTÓUñ
ó Vñ
r   r   c                   ó\  — e Zd ZU dZdZej                  j                  fZdddddœZ	e
ed<    ej                   ej                   ed	«       ej                   «        ej"                   ej$                   eej(                  e	«      Ž ¬
«       ej                   «       g¬«      «      d„ «       Zy)r   a%  Fix deprecated white/blacklist arguments to characters::

        st.characters(whitelist_categories=...) -> st.characters(categories=...)
        st.characters(blacklist_categories=...) -> st.characters(exclude_categories=...)
        st.characters(whitelist_characters=...) -> st.characters(include_characters=...)
        st.characters(blacklist_characters=...) -> st.characters(exclude_characters=...)

    Additionally, we drop `exclude_categories=` if `categories=` is present,
    because this argument is always redundant (or an error).
    z7Fix deprecated white/blacklist arguments to characters.Ú
categoriesÚexclude_categoriesÚinclude_charactersÚexclude_characters)Úwhitelist_categoriesÚblacklist_categoriesÚwhitelist_charactersÚblacklist_charactersÚ_replacementsrR   rT   )r'   rW   c                 ó&  — g }|j                   D ]ˆ  }|j                  �i| j                  j                  |j                  j                  |j                  j                  «      }|j                  t        j                  |«      ¬«      }|j                  |«       ŒŠ t        d„ |D «       «      rPt        j                  t        j                  d«      ¬«      }|D �cg c]  }t        j                  || «      sŒ|‘Œ }}|j                  |¬«      S c c}w )NrT   c           	   3   ó–   K  — | ]A  }t        j                  |t        j                  t        j                  d «      ¬«      «      –— ŒC y­w)r}   rT   N)r%   r3   r4   r5   )r   rr   s     r   r!   z6HypothesisFixCharactersArguments.fn.<locals>.<genexpr>  s-   è ø€ ÒVÀsŒq�y‰y˜œaŸe™e¬A¯F©F°<Ó,@ÔA×BÑVùs   ‚AA	r~   r^   )rW   r/   r…   Úgetr0   r6   r
   r5   ÚappendÚanyr%   r4   r3   )r9   r:   r;   rs   rr   ÚkwÚexÚas           r   rN   z#HypothesisFixCharactersArguments.fn  sß   € ð ˆØ×$Ñ$ò 	 ˆCØ�{‰{Ð&Ø×'Ñ'×+Ñ+¨C¯K©K×,=Ñ,=¸s¿{¹{×?PÑ?PÓQ�Ø×&Ñ&¬s¯x©x¸«|Ð&Ó<�Ø�N‰N˜3Õð		 ô ÑVÈgÔVÔVÜ—‘œqŸv™vÐ&:Ó;Ô<ˆBØ")Ö?˜Q¬Q¯Y©Y°q¸2¸#Õ->’qÐ?ˆGÐ?Ø×(Ñ(¨gÐ(Ó6Ð6ùò @s   ÃDÃ6DN)r=   r>   r?   r@   rA   r
   r'   r(   rB   r…   r   Ú__annotations__r%   rz   rD   r)   rd   r4   ÚOneOfÚmapr5   rN   rE   r   r   r   r   î   s³   … ñ	ð L€KØ Ÿ\™\×?Ñ?ÐAÐð !-Ø 4Ø 4Ø 4ñ	€M�8ó ð €Q‡W�WØˆ�‰Ù#Ð$FÓGà�—‘“Ø�—‘˜g˜aŸg™g¡s¨1¯6©6°=Ó'AÐBÔCØ�—‘“ðô	
ó	ñ7ó	ñ7r   r   )r@   Ú	functoolsrK   Úinspectr   r   Útypingr   Úlibcstr
   Úlibcst.matchersÚmatchersr%   Úlibcst.codemodr   Ústrr   r)   r   Ú	lru_cacherO   r   r   r   rE   r   r   ú<module>rš      sŠ   ðñó> Û ß (Ý ã Ý Ý 5ð�3ð ˜3ó ò*	ôÐ'Aô ð. ×Ññ5ó ð5ô
l7Ð*Dô l7ô^

Ð"<ô 

ô,7Ð'Aõ ,7r   