
    i+                         S r SSKrSSKrSSKJrJr  SSKJr  SSKr	SSK
Jr  SSKJr  S\S\4S jrS	 r " S
 S\5      r\R&                  S 5       r " S S\5      r " S S\5      r " S S\5      rg)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                 
   [         R                  R                  5       n[         R                  " U 5      n[	        U5      [        U5      [        U5      [        U5      /nU H  nUR                  U5      nM     UR                  $ )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        X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/hypothesis/extra/codemods.pyrefactorr   4   sr     kk((*G


4
 C+G4(1#G,(1	4J  	((-  88O    c                 j   ^  [         R                  " [        R                  R                  U 4S j5      $ )Nc                 .   > [        U4S jU  5       5      $ )Nc              3   @   >#    U  H  oR                   T:H  v   M     g 7f)Nname).0nr   s     r   	<genexpr>3match_qualname.<locals>.<lambda>.<locals>.<genexpr>Q   s     @iffnis   )all)	qualnamesr   s    r   <lambda> match_qualname.<locals>.<lambda>Q   s    #@i@@r   )mMatchMetadataIfTruer
   metadataQualifiedNameProviderr   s   `r   match_qualnamer+   I   s+       ** 	A r   c                       \ rS rSrSrSr\R                  R                  4r	\
R                  " \
R                  " \" S5      S95      S 5       rSrg)	r   U   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           	          [         R                  " U[         R                  " [         R                  " S5      [         R                  " S5      S95      (       a#  UR	                  [
        R                  " S5      S9$ U$ )Nmin_magnitudeNone)keywordvalue0r3   )r'   matchesArgNamewith_changesr
   Integerselforiginal_nodeupdated_nodes      r   	leave_Arg*HypothesisFixComplexMinMagnitude.leave_Arga   s[     99!%%(?qvvf~V
 
  ,,3;;s3C,DDr    N)__name__
__module____qualname____firstlineno____doc__DESCRIPTIONr
   r)   r*   METADATA_DEPENDENCIESr'   call_if_insideCallr+   r?   __static_attributes__rA   r   r   r   r   U   sQ     VK \\??A	'NOPr   r   c                 j    U R                  SS5      u  p[        [        R                  " U5      U5      $ )N.   )rsplitgetattr	importlibimport_module)import_pathr   fns      r   get_fnrU   l   s.      a(GC9**3/44r   c                   T    \ rS rSrSrSr\R                  R                  4r	Sr
S rSrg)r   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           
         U R                  [        R                  R                  U5      nU Vs1 s H  oDR                  iM     nn[        U5      S:w  d  UR                  U R                  5      (       a}  [        R                  " U[        R                  " [        R                  " [        R                  " 5       5      [        R                  " SS9[        R                  " 5       /S95      (       d  U$  [        [        U6 5      R                   R#                  5       nUS1:X  a#  U Vs/ s H  owR                  S:w  d  M  UPM     nn[        UR&                  5      [        U5      :  a  U$ [        R(                  " [        R*                  " S5      [        R*                  " S5      S9n[-        XbR&                  S	S
9 VV	s/ s Ht  u  pyU	R.                  (       d.  U	R0                  (       d  UR2                  [4        R6                  La  U	O-U	R9                  [        R:                  " UR                  5      US9PMv     n
nn	UR9                  U
S9$ s  snf ! [$         a    Us $ f = fs  snf s  sn	nf )z(Convert positional to keyword arguments.rN   Nr2   funcargsrX   allow_subnormal )whitespace_beforewhitespace_afterF)strict)r2   equalr^   )get_metadatar
   r)   r*   r   lenintersectionkwonly_functionsr'   r6   rJ   DoesNotMatchr7   
ZeroOrMorer   rU   
parametersvaluesModuleNotFoundErrorr^   AssignEqualSimpleWhitespacezipr2   starkindr   KEYWORD_ONLYr9   r8   )r<   r=   r>   r)   qnr$   paramspassign_nospaceargnewargss              r   
leave_Call.HypothesisFixPositionalKeywonlyArgs.leave_Call   s   $$S\\%G%GW'/0xWWx	0 	Na))$*?*?@@991%%-q||~>   
	 vy12==DDFF 788!'GA665F+FaFG|  !CK/ !2226 11"5
 f&7&7F
 G ;;#((affI<R<R.R %%chhqvv.>n%UV G 	 
 ((g(66[ 1* # 	 	  H
s*   I5)I )I$ I$ A;I)I! I!rA   N)rB   rC   rD   rE   rF   rG   r
   r)   r*   rH   ri   r{   rK   rA   r   r   r   r   r   s0     PK \\??A.`07r   r   c            
           \ rS rSrSrSr\R                  " \R                  " \R                  " \R                  " S5      \R                  " S5      5      / S95      S 5       rSrg)	r      z0Replace HealthCheck.all() with list(HealthCheck)HealthCheckr#   r\   c                     UR                  [        R                  " S5      [        R                  " [        R                  " S5      S9/S9$ )Nlistr   r5   r\   )r9   r
   r8   r7   r;   s      r   replace_healthcheck/HypothesisFixHealthCheckAll.replace_healthcheck   s>    ((&!'' 789 ) 
 	
r   rA   N)rB   rC   rD   rE   rF   rG   r'   leaverJ   	Attributer8   r   rK   rA   r   r   r   r      sN    :DKWWQVVQVVM%:AFF5MJQSTU
 V
r   r   c                   X   \ rS rSr% SrSr\R                  R                  4r	SSSSS.r
\\S	'   \R                  " \R                  " \" S
5      \R"                  " 5       \R$                  " \R&                  " \" \R*                  \
5      6 S9\R"                  " 5       /S95      S 5       rSrg)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_replacementsrY   r[   )r)   r^   c                    / nUR                    Hy  nU R                  R                  UR                  R                  UR                  R                  5      nUR                  UR                  [        R                  " U5      S95        M{     [        S U 5       5      (       aX  [        R                  " [        R                  " S5      S9nU Vs/ s H#  n[        R                  " Xv) 5      (       d  M!  UPM%     nnUR                  US9$ s  snf )Nr[   c           	   3      #    U  HB  n[         R                  " U[         R                  " [         R                  " S 5      S95      v   MD     g7f)r   r[   N)r'   r6   r7   r8   )r   ry   s     r   r!   6HypothesisFixCharactersArguments.fn.<locals>.<genexpr>  s0     VgsqyyaeeAFF<,@ABBgs   A
Ar   re   )r^   r   getr2   r3   appendr9   r
   r8   anyr'   r7   r6   )r<   r=   r>   rz   ry   kwexas           r   rT   #HypothesisFixCharactersArguments.fn  s     $$C##''(9(93;;;L;LMBNN3++CHHRL+AB % VgVVVqvv&:;<B")?'QQYYq#->q'G?((g(66 @s    D
3D
rA   N)rB   rC   rD   rE   rF   rG   r
   r)   r*   rH   r   r   __annotations__r'   r   rJ   r+   rk   r7   OneOfmapr8   rT   rK   rA   r   r   r   r      s    	 LK \\??A !- 4 4 4	M8  WW	#$FGaggs166='ABC	
	
7	
7r   r   )rF   	functoolsrQ   inspectr   r   typingr   libcstr
   libcst.matchersmatchersr'   libcst.codemodr   strr   r+   r   	lru_cacherU   r   r   r   rA   r   r   <module>r      s   >   (    53 3 *	'A . 5 5
l7*D l7^

"< 

*7'A *7r   