If the landlord finds out you have a dog or cat, and doesn't sue you for a violation within 90 days of learning of the animal's presence, the rights to terminate your lease are waived. If the building is sold, the new owner has to abide by the previous waiver, and cannot evict you because you have a pet in violation of your lease's provisions.
There are also exceptions to lease provisions that restrict pets. The law allows for pets when there is a legitimate need that can be proved. For example, recent medical research demonstrates the positive impact of pets on those suffering from clinical depression. Another illustration is the right of blind people to have seeing-eye dogs. So if you can prove that you are in need of such assistance, the Court may grant you a waiver against lease provisions prohibiting pets.
Evidence to support your position would include a doctor's letter and medical records, and especially an ongoing prescription for medication. Consequently, if you don't currently have a pet, and your lease says you can't have a dog or cat, you may be still able to get one if you're depressed.
However, be clear on this important point: if you want to keep your lease, keep your dog on a leash. A significant number of New Yorkers with dogs have the habit of taking them out for a walk, and not putting on a leash until they're at the front door of their buildings. Allowing a dog to roam freely in building common areas is fraught with legal danger.
In a recent case, a renter in a public housing project brought his unleashed dogs to the roof of his building, and one of the animals injured a police office. The tenant's lease was terminated as a result, which was upheld in Administrative Proceedings and in Court on appeal.
The same sort of thing could happen with other tenancies, because once you're involved in a lawsuit, it's impossible to predict with absolute certainty what the outcome will be. If you have a dog, protect your lease: put the leash on before you leave your apartment. Don't give the landlord leverage to win against you in Court.