internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: joke2k/faker

Issue:
Incorrect type annotation on Generator.add_provider
* Faker version: 18.3.2
* OS: MacOS

The type annotation on `Generator.add_provider` is needlessly restrictive - the implementation clearly supports passing either a type or an instance, but the type annotation only allows instances:

```python
    # faker/generator.py
    def add_provider(self, provider: "BaseProvider") -> None:
        if isinstance(provider, type):
            provider = provider(self)
```


### Steps to reproduce

1. Write code that adds a provider class to a `Generator`
2. Run mypy

```python
class MyCustomProvider(BaseProvider):
    pass

fake = Factory.create("en_US")
fake.add_provider(MyCustomProvider)
```

### Expected behavior

`mypy` check should pass

### Actual behavior

`mypy` produces an error:

```
error: Argument 1 to "add_provider" of "Generator" has incompatible type "Type[MyCustomProvider]"; expected "BaseProvider"  [arg-type]
```

Incorrect type annotation on Generator.add_provider
* Faker version: 18.3.2
* OS: MacOS

The type annotation on `Generator.add_provider` is needlessly restrictive - the implementation clearly supports passing either a type or an instance, but the type annotation only allows instances:

```python
    # faker/generator.py
    def add_provider(self, provider: "BaseProvider") -> None:
        if isinstance(provider, type):
            provider = provider(self)
```


### Steps to reproduce

1. Write code that adds a provider class to a `Generator`
2. Run mypy

```python
class MyCustomProvider(BaseProvider):
    pass

fake = Factory.create("en_US")
fake.add_provider(MyCustomProvider)
```

### Expected behavior

`mypy` check should pass

### Actual behavior

`mypy` produces an error:

```
error: Argument 1 to "add_provider" of "Generator" has incompatible type "Type[MyCustomProvider]"; expected "BaseProvider"  [arg-type]
```



Discussion:

Resolving patch:
diff --git a/faker/generator.py b/faker/generator.py
--- a/faker/generator.py
+++ b/faker/generator.py
@@ -1,7 +1,7 @@
 import random as random_module
 import re
 
-from typing import TYPE_CHECKING, Any, Callable, Dict, Hashable, List, Optional
+from typing import TYPE_CHECKING, Any, Callable, Dict, Hashable, List, Optional, Type, Union
 
 from .typing import SeedType
 
@@ -29,7 +29,7 @@ def __init__(self, **config: Dict) -> None:
         self.__config = dict(list(self.__config.items()) + list(config.items()))
         self.__random = random
 
-    def add_provider(self, provider: "BaseProvider") -> None:
+    def add_provider(self, provider: Union["BaseProvider", Type["BaseProvider"]]) -> None:
         if isinstance(provider, type):
             provider = provider(self)
 


Test patch:
Repository: joke2k/faker

Issue:
fr_FR address provider generates less than 5 digits postcode
* Faker version: master (18.9.0), bug introduced by https://github.com/joke2k/faker/pull/1852

The new provider method can generate 4 or less digits values. But french postcodes must be 5 digits long (cf https://en.wikipedia.org/wiki/Postal_codes_in_France).

Line to fix: https://github.com/joke2k/faker/blob/fa79c6b0c510274b08b46ad0f007fd1b517a9ab2/faker/providers/address/fr_FR/__init__.py#LL478C27-L478C27

### Steps to reproduce

1. generate a few postcodes with `fr_FR` address provider

### Expected behavior

5 digits values

### Actual behavior

From 3 to 5 digits values



Discussion:

Resolving patch:
diff --git a/faker/providers/address/fr_FR/__init__.py b/faker/providers/address/fr_FR/__init__.py
--- a/faker/providers/address/fr_FR/__init__.py
+++ b/faker/providers/address/fr_FR/__init__.py
@@ -469,10 +469,10 @@ def department_number(self) -> str:
 
     def postcode(self) -> str:
         """
-        Randomly returns a postcode generated from existing french depertment number.
+        Randomly returns a postcode generated from existing french department number.
         exemple: '33260'
         """
         department = self.department_number()
         if department in ["2A", "2B"]:
             department = "20"
-        return f"{department}{self.random_number(digits=5 - len(department))}"
+        return f"{department}{self.random_number(digits=5 - len(department), fix_len=True)}"


Test patch:
diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py
--- a/tests/providers/test_address.py
+++ b/tests/providers/test_address.py
@@ -870,6 +870,7 @@ def test_postcode(self, faker, num_samples):
         for _ in range(num_samples):
             postcode = faker.postcode()
             assert isinstance(postcode, str)
+            assert len(postcode) == 5
             assert (
                 postcode[:3] in department_numbers  # for 3 digits deparments number
                 or postcode[:2] == "20"  # for Corsica : "2A" or "2B"
Repository: joke2k/faker

Issue:
When attempting to generate a Finnish ssn of a specific age the provider crashes
* Faker version: 19.11.0
* OS: Windows 10

When attempting to generate a Finnish ssn of a certain age the provider crashes because ``datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))`` is always trying to generate a time within range. The ssn provider should handle situations where min_age and max_age are the same.
For example:
```
if min_age == max_age:
    age = datetime.timedelta(days=min_age * 365)
else:
    age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
```

### Steps to reproduce

1. Create a faker with fi_FI locale: ``fake = Faker('fi_FI')``
2. Call the ssn provider with the same minimum and maximum age: ``fake.ssn(min_age=50, max_age=50, artificial=True)``

### Expected behavior

The faker generates an artificial Finnish ssn that is 50 years old. 

### Actual behavior

``ValueError: empty range for randrange() (18250, 18250, 0)``



Discussion:
Do you want to submit a corresponding PR including a test to ensure that this is handled correctly?

Resolving patch:
diff --git a/faker/providers/ssn/fi_FI/__init__.py b/faker/providers/ssn/fi_FI/__init__.py
--- a/faker/providers/ssn/fi_FI/__init__.py
+++ b/faker/providers/ssn/fi_FI/__init__.py
@@ -26,7 +26,10 @@ def _checksum(hetu):
             checksum_characters = "0123456789ABCDEFHJKLMNPRSTUVWXY"
             return checksum_characters[int(hetu) % 31]
 
-        age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
+        if min_age == max_age:
+            age = datetime.timedelta(days=min_age * 365)
+        else:
+            age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
         birthday = datetime.date.today() - age
         hetu_date = "%02d%02d%s" % (
             birthday.day,


Test patch:
diff --git a/tests/providers/test_ssn.py b/tests/providers/test_ssn.py
--- a/tests/providers/test_ssn.py
+++ b/tests/providers/test_ssn.py
@@ -793,6 +793,18 @@ def test_vat_id(self):
         for _ in range(100):
             assert re.search(r"^FI\d{8}$", self.fake.vat_id())
 
+    def test_ssn_without_age_range(self):
+        current_year = datetime.now().year
+        age = current_year - 1995
+        ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True)
+        assert "95-" in ssn
+        age = current_year - 2013
+        ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True)
+        assert "13A" in ssn
+        age = current_year - 1898
+        ssn = self.fake.ssn(min_age=age, max_age=age, artificial=True)
+        assert "98+" in ssn
+
 
 class TestFrFR(unittest.TestCase):
     def setUp(self):
Repository: joke2k/faker

Issue:
hu-Hu localization gives back non-capitalized city names
* Faker version: 23.2.1
* OS: Ubuntu 22.04.3 LTS

Faker with hu-HU localization gives back non-capitalized cities, when it has either a city_prefix or city_part used in its format.

### Steps to reproduce

1. `Faker.seed(1234)`
1. `Faker("hu-HU").city()`

### Expected behavior

'Györgyháza'

### Actual behavior

'györgyháza'



Discussion:
Feel free to submit a corresponding PR.

Resolving patch:
diff --git a/faker/providers/address/hu_HU/__init__.py b/faker/providers/address/hu_HU/__init__.py
--- a/faker/providers/address/hu_HU/__init__.py
+++ b/faker/providers/address/hu_HU/__init__.py
@@ -467,3 +467,13 @@ def street_name(self) -> str:
     def building_number(self) -> str:
         numeric_part = super().random_int(1, 250)
         return str(numeric_part) + "."
+
+    # method added to fix #1996:
+    # for hu_Hu locale city_part could be first or second component of city,
+    # so city_parts tuple should contain lower-cased strings. Thus city might be lower-cased and should be capitalized
+    def city(self) -> str:
+        """
+        :example: 'Györgyháza'
+        """
+        pattern: str = self.random_element(self.city_formats)
+        return self.generator.parse(pattern).capitalize()


Test patch:
diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py
--- a/tests/providers/test_address.py
+++ b/tests/providers/test_address.py
@@ -2159,6 +2159,20 @@ def test_building_number(self, faker, num_samples):
             match = re.fullmatch(r"\d{0,3}.", building_number)
             assert match
 
+    def test_city(self, faker, num_samples):
+        # generating possible variations for cities for hu_Hu locale
+        real_cities = [city.lower() for city in HuHuAddressProvider.real_city_names]
+        cities_part_suffix = [''.join([part, suffix]) for part in HuHuAddressProvider.city_parts
+                              for suffix in HuHuAddressProvider.city_suffixes]
+        cities_prefix_part_suffix = [''.join([pref, part_suffix]) for pref in HuHuAddressProvider.city_prefs
+                                     for part_suffix in cities_part_suffix]
+        cities = real_cities + cities_part_suffix + cities_prefix_part_suffix
+        for _ in range(num_samples):
+            city = faker.city()
+            assert isinstance(city, str)
+            assert city.lower() in cities
+            assert city[0].isupper()
+
 
 class TestIdId:
     """Test id_ID address provider methods"""
Repository: joke2k/faker

Issue:
Wrong digit separator in ru_RU locale.
Faker version: 24.2.0

In Russia (and, maybe, in some other countries), a space is used as a separator of digits, not a dot. But in the Faker library (for example, in the `pricetag()` method) it's a dot ever in `ru_RU` location:

```py
>>> from faker import Faker
>>> fake = Faker('ru_RU')
>>> print(fake.pricetag())
47.116,67 р.
# ^
```

The result is `47.116,67 р.`, but it should be `47 116,67 р.`


Discussion:
Thanks for the report! Could you submit a Pull Request?
@fcurella, I think, we need to change this [line](https://github.com/joke2k/faker/blob/master/faker/providers/currency/ru_RU/__init__.py#L174) from
```py
price_formats = ["#,##", "%#,##", "%##,##", "%.###,##", "%#.###,##"]
```
to
```py
price_formats = ["#,##", "%#,##", "%##,##", "% ###,##", "%# ###,##"]
```

but I don't know, how to write tests for this feature.

Resolving patch:
diff --git a/faker/providers/currency/ru_RU/__init__.py b/faker/providers/currency/ru_RU/__init__.py
--- a/faker/providers/currency/ru_RU/__init__.py
+++ b/faker/providers/currency/ru_RU/__init__.py
@@ -171,7 +171,7 @@ class Provider(CurrencyProvider):
         ("ZWD", "Доллар Зимбабве"),
     )
 
-    price_formats = ["#,##", "%#,##", "%##,##", "%.###,##", "%#.###,##"]
+    price_formats = ["#,##", "%#,##", "%##,##", "% ###,##", "%# ###,##"]
 
     def pricetag(self) -> str:
         return (


Test patch:
diff --git a/tests/providers/test_currency.py b/tests/providers/test_currency.py
--- a/tests/providers/test_currency.py
+++ b/tests/providers/test_currency.py
@@ -1,3 +1,5 @@
+import re
+
 from unittest.mock import patch
 
 import pytest
@@ -117,6 +119,8 @@ def setup_class(cls):
         cls.currencies = cls.provider.currencies
         cls.currency_codes, cls.currency_names = tuple(zip(*cls.currencies))
 
+        cls.pricetag_pattern = re.compile(r"\d{1,3}(?:\s\d{3})*,\d{2}\sр\.")
+
     def test_currency(self, faker, num_samples):
         for _ in range(num_samples):
             cur = faker.currency()
@@ -131,6 +135,7 @@ def test_pricetag(self, faker, num_samples):
         for _ in range(num_samples):
             pricetag = faker.pricetag()
             assert isinstance(pricetag, str)
+            assert self.pricetag_pattern.fullmatch(pricetag)
 
 
 class TestCsCz:
Repository: joke2k/faker

Issue:
BE Vat Numbers should have a modulo 97 check and start wit 1 or 0
* Faker version: 25
* OS: OS. X Monterery

VAT Numbers generated in Belgium (currently set-up in the provider ssn for locale nl_BE should start with 1 or 0 and have a controle number with a module 97 check.

Refer to https://en.wikipedia.org/wiki/VAT_identification_number

### Steps to reproduce

1. Generate vat_id wit locale nl_BE


### Expected behavior

Vat numbers should be starting with BE0 or BE1 and have a module 97 check as the last two numbers





Discussion:
Suggested re-write:

`
def vat_id(self) -> str:

        vat_id_random_section = (
            '#######'
        )

        vat_id_possible_initial_numbers = (
            '0',
            '1'
        )
        """
        http://ec.europa.eu/taxation_customs/vies/faq.html#item_11
        https://en.wikipedia.org/wiki/VAT_identification_number
        :return: A random Belgian VAT ID starting with 0 or 1 and has a correct checksum with a modulo 97 check
        """
        generated_initial_number = self.random_element(vat_id_possible_initial_numbers)
        vat_without_check = self.bothify(generated_initial_number + vat_id_random_section)
        vat_as_int = int(vat_without_check)
        vat_check = 97 - (vat_as_int % 97)
        vat_check_str = f"{vat_check:0>2}"

        return "BE" + vat_without_check + vat_check_str
`
You are of course invited to propose a corresponding PR to fix this issue.

Resolving patch:
diff --git a/faker/providers/ssn/nl_BE/__init__.py b/faker/providers/ssn/nl_BE/__init__.py
--- a/faker/providers/ssn/nl_BE/__init__.py
+++ b/faker/providers/ssn/nl_BE/__init__.py
@@ -57,8 +57,24 @@ def _checksum(digits):
     vat_id_formats = ("BE##########",)
 
     def vat_id(self) -> str:
+
+        vat_id_random_section = (
+            '#######'
+        )
+
+        vat_id_possible_initial_numbers = (
+            '0',
+            '1'
+        )
         """
         http://ec.europa.eu/taxation_customs/vies/faq.html#item_11
-        :return: A random Belgian VAT ID
+        https://en.wikipedia.org/wiki/VAT_identification_number
+        :return: A random Belgian VAT ID starting with 0 or 1 and has a correct checksum with a modulo 97 check
         """
-        return self.bothify(self.random_element(self.vat_id_formats))
+        generated_initial_number = self.random_element(vat_id_possible_initial_numbers)
+        vat_without_check = self.bothify(generated_initial_number + vat_id_random_section)
+        vat_as_int = int(vat_without_check)
+        vat_check = 97 - (vat_as_int % 97)
+        vat_check_str = f"{vat_check:0>2}"
+
+        return "BE" + vat_without_check + vat_check_str


Test patch:
Repository: zestedesavoir/zds-site

Issue:
Icone d'un tuto/article absente
L'icone d'un tuto ou d'un article n'est pas visible dans le tuto/article en pleine lecture.



Discussion:

Resolving patch:
diff --git a/zds/article/views.py b/zds/article/views.py
--- a/zds/article/views.py
+++ b/zds/article/views.py
@@ -144,6 +144,7 @@ def view_online(request, article_pk, article_slug):
     article_version['pk'] = article.pk
     article_version['slug'] = article.slug
     article_version['image'] = article.image
+    article_version['thumbnail'] = article.thumbnail
     article_version['is_locked'] = article.is_locked
     article_version['get_absolute_url'] = article.get_absolute_url()
 


Test patch:
Repository: zestedesavoir/zds-site

Issue:
Ameliorer le logging de pandoc
Faire en sorte de pouvoir l'activer/désactiver via une variable bool dans la config.



Discussion:

Resolving patch:
diff --git a/zds/settings.py b/zds/settings.py
--- a/zds/settings.py
+++ b/zds/settings.py
@@ -308,6 +308,9 @@
 BOT_ACCOUNT = 'admin'
 
 PANDOC_LOC = ''
+# LOG PATH FOR PANDOC LOGGING
+PANDOC_LOG = './pandoc.log'
+PANDOC_LOG_STATE = False
 
 HAYSTACK_CONNECTIONS = {
     'default': {
@@ -339,9 +342,6 @@
 # WITHOUT THE APPROVAL OF THE ASSOCIATION COMMITEE
 MAIL_NOREPLY = 'noreply@zestedesavoir.com'
 
-# LOG PATH FOR PANDOC LOGGING
-PANDOC_LOG = './pandoc.log'
-
 # Load the production settings, overwrite the existing ones if needed
 try:
     from settings_prod import *
diff --git a/zds/tutorial/views.py b/zds/tutorial/views.py
--- a/zds/tutorial/views.py
+++ b/zds/tutorial/views.py
@@ -2740,6 +2740,12 @@ def MEP(tutorial, sha):
     out_file.write(smart_str(contenu))
     out_file.close()
 
+    # define whether to log pandoc's errors
+    
+    pandoc_debug_str = ""
+    if settings.PANDOC_LOG_STATE:
+        pandoc_debug_str = " 2>&1 | tee -a "+settings.PANDOC_LOG
+    
     # load pandoc
 
     os.chdir(tutorial.get_prod_path())
@@ -2747,7 +2753,7 @@ def MEP(tutorial, sha):
               + "pandoc --latex-engine=xelatex -s -S --toc "
               + os.path.join(tutorial.get_prod_path(), tutorial.slug)
               + ".md -o " + os.path.join(tutorial.get_prod_path(),
-                                         tutorial.slug) + ".html 2>&1 | tee -a "+settings.PANDOC_LOG)
+                                         tutorial.slug) + ".html"+pandoc_debug_str)
     os.system(settings.PANDOC_LOC + "pandoc " + "--latex-engine=xelatex "
               + "--template=../../assets/tex/template.tex " + "-s " + "-S "
               + "-N " + "--toc " + "-V documentclass=scrbook "
@@ -2756,11 +2762,11 @@ def MEP(tutorial, sha):
               + "-V geometry:margin=1in "
               + os.path.join(tutorial.get_prod_path(), tutorial.slug) + ".md "
               + "-o " + os.path.join(tutorial.get_prod_path(), tutorial.slug)
-              + ".pdf 2>&1 | tee -a "+settings.PANDOC_LOG)
+              + ".pdf"+pandoc_debug_str)
     os.system(settings.PANDOC_LOC + "pandoc -s -S --toc "
               + os.path.join(tutorial.get_prod_path(), tutorial.slug)
               + ".md -o " + os.path.join(tutorial.get_prod_path(),
-                                         tutorial.slug) + ".epub 2>&1 | tee -a "+settings.PANDOC_LOG)
+                                         tutorial.slug) + ".epub"+pandoc_debug_str)
     os.chdir(settings.SITE_ROOT)
     return (output, err)
 


Test patch:
Repository: zestedesavoir/zds-site

Issue:
Erreur dans /membres/?q=... via AJAX
Suite à l'ajout de la réponse sous forme JSON de `/membres/` ( #677 ), le GET de cette page avec le header `X-Requestes-With: XMLHttpRequest` plante, dû au fait que la lib JSON n'est pas importé dans le fichier `zds/membres/view.py`

``` bash
[07/Jun/2014 14:30:49] "GET /membres/?q=a HTTP/1.1" 500 15042
Internal Server Error: /membres/
Traceback (most recent call last):
  File "~/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "zds/member/decorator.py", line 21, in _can_read_now
    return func(request, *args, **kwargs)
  File "zds/member/views.py", line 55, in index
    data = json.dumps(results)
NameError: global name 'json' is not defined
```



Discussion:

Resolving patch:
diff --git a/zds/member/views.py b/zds/member/views.py
--- a/zds/member/views.py
+++ b/zds/member/views.py
@@ -55,6 +55,8 @@ def index(request):
             results.append(member_json)
         data = json.dumps(results)
 
+        mimetype = "application/json"
+
         return HttpResponse(data, mimetype)
 
     else:


Test patch:
Repository: zestedesavoir/zds-site

Issue:
Tutoriels membre inaccessibles via leur profil
Comme reporté par [Neabfi sur le forum](http://zestedesavoir.com/forums/sujet/381/les-bugs-deja-reportes-connus/?page=1#p3690), maintenant que les tutos en béta sont accessibles, c'est les tutos des membres qui ne le sont plus. Ainsi : 
- [les tutos de spacefox pointent vers leur version off](http://zestedesavoir.com/tutoriels/recherche/72/) avec le fil d’Ariane qui n'est pas bon.
- [La recherche des tutos en béta de spacefox](http://zestedesavoir.com/tutoriels/recherche/72/?type=beta), donc juste avec un `?type=beta` donne la bonne réponse, à savoir qu'il n'y en a pas, et le fil d'Ariane est correct. 
- La [même chose apparait chez EtoileFilante](http://zestedesavoir.com/tutoriels/recherche/160/?type=beta), avec les tutos en béta qui fonctionnent.

Je sais que le problème vient probablement de moi, est une régression et vient d'une condition mal écrite dans les templates (ie penses même qu'il s'agit de `/templates/tutorial/index.html` et `/templates/tutorial/member/online.html` et de `/zds/tutorial/view.py`). Donc si on pouvait me l'assigner, je réglerai ça.



Discussion:

Resolving patch:
diff --git a/zds/tutorial/views.py b/zds/tutorial/views.py
--- a/zds/tutorial/views.py
+++ b/zds/tutorial/views.py
@@ -1389,6 +1389,7 @@ def view_chapter(
     next_chapter = (chapter_tab[final_position + 1] if final_position + 1
                     < len(chapter_tab) else None)
     return render_template("tutorial/chapter/view.html", {
+        "tutorial": tutorial,
         "chapter": final_chapter,
         "prev": prev_chapter,
         "next": next_chapter,
@@ -1953,7 +1954,7 @@ def find_tuto(request, pk_user):
             authors__in=[u],
             sha_public__isnull=False).exclude(sha_public="").order_by("-pubdate")
 
-        return render_template("tutorial/member/index.html", {"tutorials": tutorials,
+        return render_template("tutorial/member/online.html", {"tutorials": tutorials,
                                                                "usr": u})
 
 


Test patch:
Repository: zestedesavoir/zds-site

Issue:
La liste des topics par tag envoie une 500
aller sur une url du type http://zestedesavoir.com/forums/sujets/tag/9/regression/ envoie une 500. C'est une régression par rapport à la béta privée.



Discussion:
voici un lien de ce qui a été récemment fait sur les tags si jamais ca peut aider : https://github.com/zestedesavoir/zds-site/issues/994

Non, le problème c'est les optimisations faites par @firm1.
Quand il fait des truc comme ça : `.exclude(Q(forum__group__isnull=False) & ~Q(forum__group__in=u.groups.all()))`.
Désolé, mais là mes connaissances sont dépassées. Je ne peux rien faire, si ce n'est dire que la variable u (la préposition qui précède a été autocensurée) n'existe pas.

u c'est utilisé pour user je parie... c'est dans quel fichier/ligne ?

`zds/forum/views.py` à partir de la ligne 873 (c'est mis plusieurs fois dans la fonction).


Resolving patch:
diff --git a/zds/forum/views.py b/zds/forum/views.py
--- a/zds/forum/views.py
+++ b/zds/forum/views.py
@@ -876,6 +876,7 @@ def find_topic_by_tag(request, tag_pk, tag_slug):
     tag = Tag.objects.filter(pk=tag_pk, slug=tag_slug).first()
     if tag is None:
         return redirect(reverse("zds.forum.views.index"))
+    u = request.user
     if "filter" in request.GET:
         filter = request.GET["filter"]
         if request.GET["filter"] == "solve":


Test patch: