Repository: sec-edgar/sec-edgar

Issue:
filing search have to specify filing type even though it is optional
filing search have to specify filing type, even though it is supposed to be optional

#To Reproduce
using the filing doc quickstart example but removing row on filing type 
```
from datetime import date
from secedgar import filings, FilingType

my_filings = filings(start_date=date(2020, 12, 10),
                     end_date=date(2020, 12, 15),
                     user_agent="Name (email)",
                     count=50)

my_filings_urls = my_filings.get_urls()
```



#Bug
```
AttributeError                            Traceback (most recent call last)
/var/folders/p6/282rtsj52x15882qy3mp5hpc0000gn/T/ipykernel_37555/3180531280.py in <module>
      5 company_filings = filings(cik_lookup="aapl",
      6                           user_agent="Name (email)")
----> 7 company_filings_urls = company_filings.get_urls()
      8 company_filings_urls

~/opt/anaconda3/lib/python3.9/site-packages/secedgar/core/company.py in get_urls(self, **kwargs)
    246             urls (list): List of urls for txt files to download.
    247         """
--> 248         return {
    249             key: self._get_urls_for_cik(cik, **kwargs)
    250             for key, cik in self.cik_lookup.lookup_dict.items()

~/opt/anaconda3/lib/python3.9/site-packages/secedgar/core/company.py in <dictcomp>(.0)
    247         """
    248         return {
--> 249             key: self._get_urls_for_cik(cik, **kwargs)
    250             for key, cik in self.cik_lookup.lookup_dict.items()
    251         }

~/opt/anaconda3/lib/python3.9/site-packages/secedgar/core/company.py in _get_urls_for_cik(self, cik, **kwargs)
    285         while self.count is None or len(links) < self.count:
    286             data = self.client.get_soup(self.path, self.params, **kwargs)
...
--> 263         filings_filtered = [f for f in filings if f.type.string == self.filing_type.value]
    264         return [f.filinghref.string for f in filings_filtered]
    265 

AttributeError: 'NoneType' object has no attribute 'value'
```

Hints from issue comments:
@jackmoody11: Thanks for pointing this out @juliantcchu! Are you able to help with the bug fix?

Solution patch:
diff --git a/docs/source/whatsnew/v0.5.1.rst b/docs/source/whatsnew/v0.5.1.rst
index 8698df2..917c9b2 100644
--- a/docs/source/whatsnew/v0.5.1.rst
+++ b/docs/source/whatsnew/v0.5.1.rst
@@ -5,6 +5,7 @@ Highlights
 ~~~~~~~~~~
 
 - Pass user agent to ``CIKLookup``. Thanks to clintmoyer!
+- Fix bug preventing ``filing_type`` being set to ``None`` in ``CompanyFilings``
 
 Contributors
 ~~~~~~~~~~~~
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 2ea1ff2..1547a76 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,5 +1,6 @@
 aiohttp < 4.0.0
-pytest
+click
 flake8
 pydocstyle >= 4.0.0
-click
\ No newline at end of file
+pytest
+pytest-asyncio
\ No newline at end of file
diff --git a/secedgar/core/company.py b/secedgar/core/company.py
index 2d752bd..d546fb2 100644
--- a/secedgar/core/company.py
+++ b/secedgar/core/company.py
@@ -260,8 +260,10 @@ class CompanyFilings(AbstractFiling):
             list of str: List of URLs that match ``filing_type``.
         """
         filings = data.find_all("filing")
-        filings_filtered = [f for f in filings if f.type.string == self.filing_type.value]
-        return [f.filinghref.string for f in filings_filtered]
+        if self.filing_type is None:
+            return [f.filinghref.string for f in filings]
+        else:
+            return [f.filinghref.string for f in filings if f.type.string == self.filing_type.value]
 
     # TODO: Change this to return accession numbers that are turned into URLs later
     def _get_urls_for_cik(self, cik, **kwargs):
@@ -328,8 +330,12 @@ class CompanyFilings(AbstractFiling):
 
         inputs = []
         for cik, links in urls.items():
-            formatted_dir = dir_pattern.format(cik=cik,
-                                               type=self.filing_type.value)
+            # If no filing type, just leave all filings for CIK under directory named after CIK
+            if self.filing_type is None:
+                formatted_dir = cik
+            else:
+                formatted_dir = dir_pattern.format(cik=cik,
+                                                   type=self.filing_type.value)
             for link in links:
                 formatted_file = file_pattern.format(
                     accession_number=self.get_accession_number(link))


Test patch:
diff --git a/secedgar/tests/core/test_company.py b/secedgar/tests/core/test_company.py
index 26c1375..6a02119 100644
--- a/secedgar/tests/core/test_company.py
+++ b/secedgar/tests/core/test_company.py
@@ -234,8 +234,11 @@ class TestCompanyFilings:
         assert first_txt_url.split(".")[-1] == "txt"
 
     @pytest.mark.parametrize("new_filing_type",
-                             (FilingType.FILING_10K, FilingType.FILING_8K,
-                              FilingType.FILING_13FHR, FilingType.FILING_SD))
+                             (FilingType.FILING_10K,
+                              FilingType.FILING_8K,
+                              FilingType.FILING_13FHR,
+                              FilingType.FILING_SD,
+                              None))
     def test_filing_type_setter(self, mock_user_agent, new_filing_type):
         f = CompanyFilings(user_agent=mock_user_agent,
                            cik_lookup="aapl",
@@ -335,7 +338,17 @@ class TestCompanyFilings:
     def test_filing_save_multiple_ciks_smoke(self, tmp_data_directory,
                                              real_test_client):
         f = CompanyFilings(["aapl", "amzn", "msft"],
-                           FilingType.FILING_10Q,
+                           filing_type=FilingType.FILING_10Q,
+                           client=real_test_client,
+                           count=3)
+        f.save(tmp_data_directory)
+        assert len(os.listdir(tmp_data_directory)) > 0
+
+    @pytest.mark.asyncio
+    @pytest.mark.smoke
+    def test_filing_company_none_filing_type(self, tmp_data_directory, real_test_client):
+        f = CompanyFilings(["aapl", "msft", "amzn"],
+                           filing_type=None,
                            client=real_test_client,
                            count=3)
         f.save(tmp_data_directory)